//
//  WatchViewController.m
//  梁森直播
//
//  Created by 中创 on 2020/4/27.
//  Copyright © 2020 LS. All rights reserved.
//

#import "WatchViewController.h"

@import TXLiteAVSDK_Professional;

/// 直播页面
@interface WatchViewController ()

@property (nonatomic, strong) TXLivePlayer * txLivePlayer;

@end

@implementation WatchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

- (void)setupUI{
    self.view.backgroundColor = [UIColor whiteColor];
    UIView * myView = [UIView new];
    [self.view addSubview:myView];
    myView.frame = CGRectMake(0, 100, self.view.frame.size.width, 200);
    
    TXLivePlayer *_txLivePlayer = [[TXLivePlayer alloc] init];
    //用 setupVideoWidget 给播放器绑定决定渲染区域的view，其首个参数 frame 在 1.5.2 版本后已经被废弃
    [_txLivePlayer setupVideoWidget:CGRectMake(0, 0, 0, 0) containView:myView insertIndex:0];
    self.txLivePlayer = _txLivePlayer;
    
    UIButton * playBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:playBtn];
    playBtn.frame = CGRectMake(100, 250, 100, 30);
    playBtn.center = self.view.center;
    [playBtn addTarget:self action:@selector(startPlay) forControlEvents:UIControlEventTouchUpInside];
}
- (void)startPlay{
    NSString* flvUrl = @"http://2157.liveplay.myqcloud.com/live/2157_xxxx.flv";
    [self.txLivePlayer startPlay:flvUrl type:PLAY_TYPE_LIVE_FLV];
}
- (void)stopPlay{
    // 停止播放
    [self.txLivePlayer stopPlay];
    [self.txLivePlayer removeVideoWidget]; // 记得销毁view控件
}
@end
